// import '@/assets/reset.css'

import { createApp } from 'vue'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import PanelHead from '@/components/panelHead.vue'



import App from './App.vue'

import router from './router'
// vueX引入
import store from './store'

// 刷新后的动态路由添加
// 存储数据的地方添加日志（假设这里是存储的代码）


const localData = localStorage.getItem('pz-v3pzxxx')
console.log(localData)
if(localData){
  store.commit('dynamicMenu', JSON.parse(localData).menu.routerList)
  store.state.menu.routerList.forEach(item => {
    router.addRoute('main' , item)
  })

}



// 路由守卫
router.beforeEach((to, from ) => {
  const token = localStorage.getItem('pz_token')

  // 非登录页面token不存在
  if(!token && to.path !== '/login'){
    return '/login'
  } else if(token && to.path === '/login'){
    return '/'
  } else{
    return true
  }
})




const app = createApp(App)


import * as ElementPlusIconsVue from '@element-plus/icons-vue'

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.component('PanelHead',PanelHead)

app.use(ElementPlus)
app.use(router)
// vueX挂载 说是得写在router挂载之后
app.use(store)
app.mount('#app')
